/*
attachment 
Author: 朱希望
Syntax: $(element).chooseStaff({
			hiddenName:"attachment.attachmentId",
		});
*/
(function($) {
  $.fn.memberReg = function(options) {
	  var defaults = {   
	            target      : "",   			//弹出框DIV的ID名字
	            staffId		: "",
	            title		: "",			//弹出框上面显示的title
	            btnName		: "",
	            isReg		: "",
	            equId		: ""
	        };   
	  
	        options = $.extend(defaults, options);   
	        //把弹出框的DIV和要传到后台的ID隐藏域加上
	        $('body').append("<div id='"+options.target+"' title='"+options.title+"' style='display:none;'> </div>"); 
	       // $('form').append("<input id='"+options.hiddenId+"' type='hidden' name='"+options.hiddenName+"' value=''");
	       // $('form').append(" <@s.hidden name='"+options.hiddenName+"' id='"+options.hiddenId+"'></@s.hidden>");
	        var target = "#"+options.target;
	       	 $(target).append(
	       			'<table align="center" border="1" width="100%">'+
	       		  '<tr class="ui-state-default">'+
	       	    	'<td style="width:30%" >&nbsp;&nbsp;考勤机权限：</td>'+
	       	    	'<td style="width:70%">'+
	       			 '<select name="privilege" id="privilege2">'+
	       			 	'<option value="0">普通用户</option>'+
	       			 	'<option value="1">超级管理员</option>'+
	       			 	'<option value="2">登记管理员</option>'+
	       			 	'<option value="3">设置管理员</option>'+
	       			 '</select></td></tr><tr class="ui-state-default">'+
	       			'<td colspan="2" style="text-align:center">'+
	       			  '<div class="action" align="center">'+ 
	       			  '<button type="button" id ="regBtn"  Class="btn"><span id="btnName">'+options.btnName+'</span></button>&nbsp;&nbsp;'+
	       			  '<button type="button" id="cancelBtn" class="btn"><span>取消</span></button></div></td></tr></table>');
	      //员工出框开始
	    	$(target).dialog({
	    		bgiframe: true,
	    		autoOpen:false,
	    		resizable :false,
	    		position: 'center',
	    		width: 500,
	    		height: 200,
	    		modal: true
	    	});
	        $(target).find('#regBtn').bind('click',function(){
	         	var privilege = $(target).find('#privilege2').val();
	         	dataStr = "equId="+equId+"&staffId="+staffId+"&privilege="+privilege;
           		var url = "";
           		if(options.isReg) {
           			url ="registerEnrollData.action";
           		} else {
           			url ="modifyPrivilege.action";
           		}
           		$.ajax({   
           		    url:url,   
           		    type:'POST',   
           		    dataType: 'json',   
           		    data:dataStr,   
           			beforeSend:function(xmlhttprequest){
           				
           		 	},
           			success:function(data){
           				alert(data.msg);
           				gridReload();
           			},
           			error:function(data){
           				alert("出错了！");
           			}
           		});
           		 $(target).dialog('close');
  				});
              $(target).find('#cancelBtn').bind('click',function(){
            	  $(target).dialog('close');
              });
	    	return  $(this).click(function(){  
	              $(target).dialog('open');
	                return false;   
	            });    
  }
})(jQuery);
